﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using SeizyUtils.Common.Utilities;
using SeizyUtils.Common.Data;

namespace SeizyUtils.Binder
{
    class DataBinder : IDataBinder
    {

        public T bindObject<T>(IRecord record, T data) 
        {

            Type type = data.GetType();

            foreach (PropertyInfo member in type.GetProperties())
            {
                IColumn column = DefinitionManager.getColumn(member.Name);
                object value = record.GetObject(column);
                member.GetSetMethod().Invoke(data, new object[]{ TypeUtils.castType(value, member.PropertyType) });
            }

            return data;

        }

    }
}
